package com.jcnet.bizaia;
import com.mozillaonline.providers.DownloadManager;
import com.mozillaonline.providers.downloads.Downloads;
import com.squareup.picasso.Downloader;

import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;
import android.widget.ListView;

public class JCDownloadList extends JCSimpleSherlockActivity {

	private DownloadManager mDownloadManager;
	private Cursor mDateSortedCursor;
	private Cursor mSizeSortedCursor;
	
	private Cursor myCursor;

	private ListView listView;


	 private int mStatusColumnId;
	    private int mIdColumnId;
	    private int mLocalUriColumnId;
	    private int mMediaTypeColumnId;
	    private int mReasonColumndId;

	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);
		setContentView(R.layout.comm_simple_list_base);

		listView = (ListView)findViewById(R.id.commSimpleListViewBase);

		mDownloadManager = new DownloadManager(getContentResolver(),
				getPackageName());
		mDownloadManager.setAccessAllDownloads(true);
		
		DownloadManager.Query baseQuery = new DownloadManager.Query()
		.setOnlyIncludeVisibleInDownloadsUi(true);
		
		DownloadManager.Query myqQuery = new DownloadManager.Query().setFilterByStatus(8);

		
		

		mDateSortedCursor = mDownloadManager.query(baseQuery);
		
		
		mSizeSortedCursor = mDownloadManager.query(baseQuery.orderBy(
				DownloadManager.COLUMN_TOTAL_SIZE_BYTES,
				DownloadManager.Query.ORDER_DESCENDING));
		
		myCursor = mDownloadManager.query(myqQuery);
		
		

		listView.setAdapter(new SimpleCursorAdapter(this, R.layout.comm_text, myCursor, 
				new String[]{DownloadManager.COLUMN_MEDIA_TYPE},
				new int[]{R.id.comm_text}
		));
		
		
		while (myCursor.moveToNext()) {
			System.out.println(myCursor.getString(myCursor.getColumnIndex(DownloadManager.COLUMN_TITLE)));
			System.out.println(myCursor.getString(myCursor.getColumnIndex(DownloadManager.COLUMN_ID)));
			System.out.println(myCursor.getString(myCursor.getColumnIndex(DownloadManager.COLUMN_LAST_MODIFIED_TIMESTAMP)));
			System.out.println(myCursor.getString(myCursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)));
			System.out.println(myCursor.getString(myCursor.getColumnIndex(DownloadManager.COLUMN_MEDIA_TYPE)));
			
			System.out.println("______________________________________________");
		}
		
	}

}
